const express = require('express');

const data = require('./data/newdata.json');

// 1.导入
const ejs = require('ejs');

const app = express();

//2. 配置模板引擎对应解析目录
app.set("views",__dirname+'/html');
//3. 渲染文件方法及文件后缀名设置 
app.engine('html',ejs.renderFile);

app.get('/',(req,res)=>{
    let abc = 666;
    // 4. 渲染模板
    res.render("index.html",{abc});
});

app.get('/newlist',(req,res)=>{
    res.render("newlist.html",{data});
});

app.get('/detail/:id',(req,res)=>{
    // console.log(req.params.id);
    let result = data.find(item=>item.id===req.params.id);
    res.render("detail.html",{result});
});


app.listen(80,()=>{
    console.log('success');
});